<template>
  <div>
    <h1>三级分类页面</h1>
    <el-tree :data="data" @node-click="nodeClick" :props="defaultProps" :expand-on-click-node="false">
    </el-tree>

  </div>
</template>


<script>
export default {
  data() {
    return {
      data: [],
      defaultProps: {
        children: "children",
        label: "name",
      }
    };
  },
  methods: {

    nodeClick(node){
      //console.log("被点击的对象:",node);

      if(node.catLevel==3){
        console.log("子组件需要传递的对象:",node);
        this.$emit('tree-node-click',node)

      }
    },

    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;

      this.$http({
        url: this.$http.adornUrl("/product/category/tree/list"),
        method: "get",
        params: this.$http.adornParams(),
      }).then(({ data }) => {
        console.log(data);
        this.data = data.data;
      });
    },
  },
  created() {
    this.getDataList();
  },
};
</script>
